package controller;

import com.alibaba.fastjson.JSON;
import mapper.SysUsersMapper;
import model.dto.SysMenuDto;
import model.dto.SysSubMenuDto;
import model.dto.SysUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.SysMenusService;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @className: controller.SysMenusController
 * @author: Xia
 * @create: 2023-03-13 16:39
 */
@Controller
@RequestMapping("menu")
public class SysMenusController {
    @Autowired
    private SysMenusService service;
    @Autowired
    private SysUsersMapper mapper;

    @RequestMapping("menus")
    @ResponseBody
    public String menus(HttpSession session , Model model){
        SysUserDto userSession = (SysUserDto) session.getAttribute("userSession");
        SysUserDto userType = mapper.getUserById(userSession.getId());
        List<SysMenuDto> menusList = service.getMenusList(userType.getUserType());
        return JSON.toJSONString(menusList);
    }
}
